package com.smileus.integration.cluster.divert;

//闭区间
@SuppressWarnings("unchecked")
public class CloseInterval implements Comparable {
	private Integer min;
	private Integer max;

	public Integer getMin() {
		return min;
	}

	public void setMin(Integer min) {
		this.min = min;
	}

	public CloseInterval() {
		super();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((max == null) ? 0 : max.hashCode());
		result = prime * result + ((min == null) ? 0 : min.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		CloseInterval other = (CloseInterval) obj;
		if (max == null) {
			if (other.max != null)
				return false;
		} else if (!max.equals(other.max))
			return false;
		if (min == null) {
			if (other.min != null)
				return false;
		} else if (!min.equals(other.min))
			return false;
		return true;
	}

	public CloseInterval(Integer min, Integer max) {
		super();
		this.min = min;
		this.max = max;
	}

	public Integer getMax() {
		return max;
	}

	public void setMax(Integer max) {
		this.max = max;
	}

	public boolean in(Integer value) {
		return (min <= value && value <= max);
	}

	public int compareTo(Object o) {
		if (o == null) {
			throw new RuntimeException("被比较的区间对象不能为空。");
		}
		CloseInterval cp = (CloseInterval) o;
		int mincp = this.min.compareTo(cp.getMin());
		int maxcp = this.max.compareTo(cp.getMax());
		return (mincp == 0 ? maxcp : mincp);
	}
}
